import axios from '@/libs/api.request'
import qs from 'qs'




export const getTableData = () => {
  return axios.request({
    url: 'get_table_data',
    method: 'get'
  })
}

export const getDragList = () => {
  return axios.request({
    url: 'get_drag_list',
    method: 'get'
  })
}

export const errorReq = () => {
  return axios.request({
    url: 'error_url',
    method: 'post'
  })
}

export const saveErrorLogger = info => {
  return axios.request({
    url: 'api/common/saveError',
    data: qs.stringify(info),
    method: 'post',
    headers: {
      'Content-type': 'application/json'
    }
  })
}

export const uploadImg = formData => {
  return axios.request({
    url: 'image/upload',
    data: formData
  })
}

export const getOrgData = () => {
  return axios.request({
    url: 'get_org_data',
    method: 'get'
  })
}

export const getTreeSelectData = () => {
  return axios.request({
    url: 'get_tree_select_data',
    method: 'get'
  })
}


///************用户管理 start****************///
/**
 * 获取所有用户数据
 * @returns {AxiosPromise}
 */
export const getUserTableData = () =>{
  return axios.request({
    url: '/api/system/user',
    method: 'get'
  })
}
export const getUserTableDataByPageAndSize = (page,size) =>{
  return axios.request({
    url: `/api/system/user/${size}/${page}`,
    method: 'get'
  })
}
export const addUserData = (data) =>{
  //data.roles = JSON.stringify(data.roles);
  return axios.request({
    url: '/api/system/user',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    data:JSON.stringify(data),
    method: 'post'
  })
}
export const updateUserData = (data) =>{
  return axios.request({
    url: '/api/system/user',
    data:JSON.stringify(data),
    method: 'put'
  })
}
export const deleteUserData = (data) =>{
  return axios.request({
    url: '/api/system/user',
    data:qs.stringify(data),
    method: 'delete'
  })
}
///************用户管理 end******************///
///************角色管理 start****************///
export const addRoleData= data=>{
  return axios.request({
    url:"api/system/role",
    data:qs.stringify(data),
    method:'post'
  })
}
/**
 * 获取所有角色数据
 * @returns {AxiosPromise}
 */
export const getRoleTableData = () =>{
  return axios.request({
    url: '/api/system/role',
    method: 'get'
  })
}
/**
 * 获取所有角色数据
 * @returns {AxiosPromise}
 */
export const getRoleTableDataByPageAndSize = (page,size) =>{
  return axios.request({
    url: `/api/system/role/${size}/${page}`,
    method: 'get'
  })
}
///**********角色管理 end****************///
///**********权限管理 start* ************///
export function addPermission(data) {
  return axios.request({
    url:"api/system/permission",
    data:qs.stringify(data),
    method:'post'
  })
}
/**
 * 获取所有权限数据
 * @returns {AxiosPromise}
 */
export const getPermissionTableData = () =>{
  return axios.request({
    url: '/api/system/permission',
    method: 'get'
  })
}
/**
 * 获取所有权限数据
 * @returns {AxiosPromise}
 */
export const getPermissionTableDataByPageAndSize = (page,size) =>{
  return axios.request({
    url: `/api/system/permission/${size}/${page}`,
    method: 'get'
  })
}
export const getPermissionData = () =>{
  return axios.request({
    url: `/api/system/permission`,
    method: 'get'
  })
}
///************权限管理 end***************///
///************资源管理 start*************///
export const addResource =(data) => {
  return axios.request({
    url: '/api/system/resource',
    method: 'post',
    data:qs.stringify(data),
  })
}
/**
 * 获取所有资源数据
 * @returns {AxiosPromise}
 */
export const getResourceTableData = () =>{
  return axios.request({
    url: '/api/system/resource',
    method: 'get'
  })
}
/**
 * 获取所有资源数据
 * @returns {AxiosPromise}
 */
export const getResourceTableDataByPageAndSize = (page,size) =>{
  return axios.request({
    url: `/api/system/resource/${size}/${page}`,
    method: 'get'
  })
}
/**
 * 获取所有资源数据
 * @returns {AxiosPromise}
 */
export const getImgUrl = (data) =>{
  return axios.request({
    url: '/api/img/getImg',
    method: 'post',
    async:false,
    data:qs.stringify(data),
  })
}
///************资源管理 end******************///
///************房源管理 start****************///
export const getAllRoom=()=>{
    return axios.request({
      url:'api/room/management'
    })
}
export const getAllRoomByPageAndSize=(page,size)=>{
  return axios.request({
    url:`api/room/management/${size}/${page}`,
    type:'get'
  })
}
export const getAllStatus=()=>{
  return axios.request({
    url:'api/common/status'
  });
}
export const getRoomTableData = ()=>{
  return axios.request({
    url: 'api/room/management',
    method: 'get'
  })
}
export const addRoom = (data)=>{
  return axios.request({
    url:'api/room/management',
    method:'post',
    header:{
      'Content-Type':'application/x-www-form-urlencoded'
    },
    data:qs.stringify(data),
  })
}
export const updateRoom = (data)=>{
  return axios.request({
    url:'api/room',
    method:'put',
    header:{
      'Content-Type':'application/x-www-form-urlencoded'
    },
    data:data,
  })
}
export const deleteRoom = (data)=>{
  return axios.request({
    url:'api/room',
    method:'delete',
    header:{
      'Content-Type':'application/x-www-form-urlencoded'
    },
    data:data,
  })
}
/****************房间类型*******************/
export const getAllRoomType= ()=>{
  return axios.request({
    url:`api/room/management/roomType`,
    method:'get',
    header:{
      'Content-Type':'application/x-www-form-urlencoded'
    },
  })
}

export const getAllRoomTypeByPageAndSize = (page,size)=>{
  return axios.request({
    url:`api/room/management/roomType/${size}/${page}`,
    method:'get',
    header:{
      'Content-Type':'application/x-www-form-urlencoded'
    },
  })
}

/*******************基础设施**********************/





/*******************订单列表 *************************/
export const getAllOrderFormByPageAndSizeAndStatus = (page,size,status)=>{
  return axios.request({
    url:`api/system/order/${status}/${size}/${page}`,
    method:'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
  })
}
export const getAllOrderFormByPageAndSizeIsNotFinnish = (page,size)=>{
  return axios.request({
    url:`api/system/order/${size}/${page}`,
    method:'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
  })
}
/*******************员工管理*************************/
export const getAllEmployeeByPageAndSize = (page,size)=>{
  return axios.request({
    url:`api/employee/${size}/${page}`,
    method:'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
  })
}

/*******************会员管理*************************/
export const getAllVipUserByPageAndSize = (page,size)=>{
  return axios.request({
    url:`api/customer/${size}/${page}`,
    method:'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
  })
}

/*******************公共接口*************************/

export const getStatus=(val)=> {
      axios.request({
        url:`api/common/status/${val}`,
        method:'get',
        headers: {
          'Content-Type': 'application/json;charset=UTF-8'
        },
      }).then(
        o=>{
          if (o.data.code == 200){
            return JSON.parse(o.data.object);
          }
          return {code: 0, value: '未知状态',color:"#ff0000"}
        }
      ).catch(o=>{
        return {code: 0, value: '未知状态',color:"#ff0000"}
      })
}
